package lesson12;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Test03 {

    public void loadProperties(Properties properties){
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("obj.properties");
            properties.load(fis);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public void saveProperties(Properties properties){
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("obj.properties");
            properties.store(fos,null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("name","刘备");
        properties.setProperty("age","20");
        properties.setProperty("gender","男");

        Test03 test03 = new Test03();
        test03.saveProperties(properties);

//        test03.loadProperties(properties);
//        System.out.println(properties);

    }
}
